package control;

import java.io.IOException;
import java.util.Scanner;

import matching.AimlParser;

public class Chatterbot {
	public static void main(String[] args) throws IOException {
		int count = 0;
		boolean isLearning = false;
		String sen = "";
		String name = "Human";
		Scanner scanIn = new Scanner(System.in);
		ProcessedInput input = new ProcessedInput();
		
		do {
			if (0 == count) {
				System.out.println("Welcome to Chatbot 2013");
				System.out.println("Chatbot: " + "Hi, What is your name ?");
			}
			sen = scanIn.nextLine();
			input.setInput(sen);
			
			if (0 == count) {
				//set Name of human
				System.out.println("Chatbot: " + "nice to meet you, " + name);
			} else {
				if (isLearning) {
					input.setLearning(true);
					isLearning = false;
				}
				ProcessedOutput answer = AimlParser.getInstance().getAnswers(input);

				if (null != answer) {
					System.out.println(answer.getResponse());
					if (!answer.getExist()) {
						isLearning = true;
					}
				}
			}
			++count;
		} while (!sen.toLowerCase().equals("exit"));

		scanIn.close();
	}
}
